package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.dao.CarDAO;
import edu.hwadee.entity.Car;
import edu.hwadee.service.CarService;

/**
* @author luhaojian
* @version ����ʱ�䣺2018��8��9�� ����11:51:09
* ���ܣ�������Ϣ�ӿ�ʵ���࣬������ɾ����ĸ�����
*/
public class CarServiceImpl extends BasicServiceImpl implements CarService {
	
	
	
	/**
	 * 
	* @author luhaojian
	* @version ����ʱ�䣺2018��8��9�� ����11:51:17
	* ���ܣ���ӳ�����Ϣ
	 */
	public boolean add(Car car) {
		try {
			getCarDao().save(car);
			//carDAO.save(car);
			return true;
		} catch (Exception e) {
			System.out.println("���ʧ��");
			return false;
		}
		
	}

	/**
	 * 
	* @author luhaojian
	* @version ����ʱ�䣺2018��8��9�� ����11:54:44
	* ���ܣ����ݳ����������������Ϣʵ����
	 */
	public Car search(int carID) {
		System.out.println(getCarDao());
		System.out.println(carID);
		Car car=getCarDao().findById(carID);
		
		System.out.println(car.getStaff().getEducation());
		
		return car;
	}

	
	public List<Car> searchList(Car car){
		try {
			return (List<Car>)getCarDao().findByExample(car);
		} catch (Exception e) {
			return null;
		}
		
		
	}
	
	public boolean update(Car car) {

		try {
			getCarDao().merge(car);
			return true;
		} catch (Exception e) {
			return false;
		}
		
	}

	@Override
	public boolean delete(Car car) {
		try {
			getCarDao().delete(car);
			return true;
		} catch (Exception e) {
			return false;
		}
		
	}

	@Override
	public List<Car> getList() {
		//System.out.println(getCarDao());
			List<Car> list=(List<Car>)getCarDao().findAll();
			
		for(Car car:list){
			System.out.println(car.getColor()
					+car.getCarNumber());
			if(list!=null)
				return list;
				
			
			else return null;
		
		}
		return list;
	}

}
